package com.travel.security.service;

import com.travel.mapper.user.UserMapper;
import com.travel.model.entity.auth.User;
import com.travel.service.impl.User.UserDetailsImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
//用户详情服务 根据用户名加载用户详情
@Service
@RequiredArgsConstructor
public class CustomUserDetailsService implements UserDetailsService {
    
    private final UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.findByUsername(username)
            .orElseThrow(() -> new UsernameNotFoundException("未找到用户: " + username));
            
        return UserDetailsImpl.build(user);
    }
} 